<?php

ini_set("memory_limit","150M");

require_once('BaseModel.php');
require_once('configs/Config.php');
require_once('DBUtils.php');

class Application_Model_Objects extends BaseModel
{
	protected $_name = 'objects';
	protected $_primary = array('profile_id');
	
	public function __construct($from, $count, $oids)
	{
		parent::__construct(null, false);
		try {
			if (!is_numeric($count))
				$count = SolrConfig::LEVEL0_COUNT;
			$statement = "Set names 'utf8'";
			//Fetch the data
			//Create the SQL statement to select the data.
			$this->_setupDatabaseAdapter();
//			$this->results = $this->_db->query($statement);

			$statement = $this->select(Zend_Db_Table::SELECT_WITH_FROM_PART)
						->setIntegrityCheck(false)
						->join('obj_def', $this->_name.'.oid=obj_def.oid')
						->join('keywords', 'obj_def.keywordsID=keywords.keywordsID')
						->join('terms', $this->_name.'.termid=terms.id', array('content'=>'content_en'))						
						->where(DBUtils::buildOrQuery('keyword', $oids))
						->limit($count, $from)
						->order('profile_id');

//			die( $statement->__toString());
						
//			var_dump($this->_db);
			
			//"SELECT profile_id, content, mark, oid
              //FROM objects
            //WHERE profile_id < $count and (".buildOidOr($oids).") order by profile_id";
			//Fetch the data
			$results = $this->fetchAll ( $statement, array(), Zend_Db::FETCH_OBJ );
		} catch ( Zend_Db_Exception $e ) {
			echo $e->getMessage ();
		}
		
		$this->setData ( $results );
	}	
	
	
	
	public function createDefaultData()
	{
		
	}
	
	public function abstractLoad($id)
	{
		
	}
}
